<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>编辑预收记录</title>
    <script type="text/javascript">
      Ext.onReady(function(){
        var receivableId = Ext.create('Ext.form.field.Hidden', {
          name: 'id'
        });
        
        //所有客户
        var customer = Ext.create('Ext.form.ComboBox', {
          fieldLabel: '到客户',
          store: customerAllInfoStore,
          allowBlank: false,
          blankText: "客户必须选择",
          emptyText: '请选择...',
          valueField: 'id',
          displayField: 'name',
          name: 'customer_id',
          loadingText: '搜索中...',
          minChars: 0,
          anchor: '100%',
          pageSize: 10
        });

        var salesStrategy = Ext.create('Ext.form.ComboBox', {
          store: salesStrategyStore,
          fieldLabel: '销售策略',
          allowBlank: false,
          blankText: "销售策略必须选择",
          emptyText: '请选择...',
          valueField: 'id',
          displayField: 'name',
          name: 'sales_strategy_id',
          loadingText: '搜索中...',
          anchor: '100%',
          editable:false,
          minChars: 0
        });
        
        //首付金额
        var recAmount = Ext.create('Ext.form.field.Number', {
          fieldLabel: '收款金额',
          name:"amount",
          allowBlank: false,
          allowDecimals: true,
          minValue: 0,
          anchor: '100%'
        });


        var paymentType = Ext.create('Ext.form.ComboBox', {
          fieldLabel: '收款方式',
          store: paymentTypeStore,
          valueField:'text',
          displayField:'text',
          typeAhead: true,
          mode: 'local',
          name:'payment_type',
          emptyText:'请选择收款方式...',
          allowBlank: false,
          anchor: '95%'
        });

        var actionDate = Ext.create('Ext.form.field.Date', {
          fieldLabel: '收款日期',
          name: 'action_date',
          format: 'Y-m-d', //格式化日期
          //disabledDays: [0,6],	//不让选择周六，周日
          //disabledDaysText: "周末要休息",
          invalidText: "您输入的日期格式不对，正确格式为2010-01-18",
          allowBlank: false,
          blankText: "收款日期必须选择",
          emptyText: '收款日期...',
          anchor: '95%'
        });
        
        //收款备注
        var desc = Ext.create('Ext.form.field.TextArea', {
          fieldLabel: '收款备注',
          name: 'description',
          anchor: '100%',
          height:140
        });

        var submitButton = Ext.create('Ext.Button', {
          text: '提交',
          iconCls: 'finding',
          handler: function(){
            if (editReceivableForm.form.isValid()) {
              this.disable();
              editReceivableForm.form.submit({
                method: 'GET',
                success: function(result, response){
                  if (response.result.info == "成功") {
                    //添加成功后，隐藏窗口，并刷新Grid
                    editReceivableNoSaleOrderWin.destroy();
                  }
                  else {
                    Ext.MessageBox.alert('消息', response.result.info);
                  }
                },
                failure: function(result, response){
                  Ext.MessageBox.alert('提示', result.responseText);
                  editReceivableNoSaleOrderWin.destroy();
                }
              });
            }
            else {
              Ext.MessageBox.alert('错误提示', '请按要求填写必输选项.');
            }
          }
        });
        
        var editReceivableForm = Ext.create('Ext.form.Panel', {
          fieldDefaults: {
            labelWidth: 55,
            labelAlign: 'right'
          },
          url:'/receivables/update',
          frame:true,
          //title: '添加用户',
          bodyStyle:'padding:5px 5px 0',
          width: 640,
          reader: Ext.create('Ext.data.reader.Json',{
            model: 'Receivable',
            root: 'root'
          }),
          //height:300,
          items: [{
              layout: 'column',
              xtype: 'container',
              items: [{
                  columnWidth: .65,
                  layout: 'anchor',
                  xtype: 'container',
                  items: [customer]
                }, {
                  columnWidth: .35,
                  layout: 'anchor',
                  xtype: 'container',
                  items: [salesStrategy]
                }]
            },{
              layout: 'column',
              xtype: 'container',
              items: [{
                  columnWidth: .3,
                  layout: 'anchor',
                  xtype: 'container',
                  items: [recAmount]
                }, {
                  columnWidth: .35,
                  layout: 'anchor',
                  xtype: 'container',
                  items: [paymentType]
                }, {
                  columnWidth: .35,
                  layout: 'anchor',
                  xtype: 'container',
                  items: [actionDate]
                }]
            },{
              layout: 'column',
              xtype: 'container',
              items: [{
                  columnWidth: 1,
                  layout: 'anchor',
                  xtype: 'container',
                  items: [desc]
                }]
            },receivableId],
          buttons: [submitButton,{
              text: '关闭',
              iconCls: 'exit',
              handler: function(){
                editReceivableNoSaleOrderWin.destroy();
              }
            }]
        });

        editReceivableForm.form.load({
          url: '/receivables/getReceivableById?id=<%=params[:id]%>',
          method : 'GET',
          waitMsg: '正在载入数据...',
          success: function(form, action){
          },
          failure: function(form, action){
            Ext.MessageBox.alert('提示信息', '信息加载失败');
          }
        });
        editReceivableForm.render('edit_receivable_form');
      })
    </script>
  </head>
  <body>
    <div id="edit_receivable_form"></div>
  </body>
</html>
